export function ReadingIncrement(params) {
  console.log(params);
  let nodes = [];
  let links = [];
  // let key = params.keys
  // let NODE = key.toString().split(",")//详情中本身的数据
  let obj = {
    id: 0,
    name: params.keys.title,
    key: params.keys.id,
    keys: params.keys.keys,
    category: 0
  };
  nodes.push(obj);
  params.knowledges &&
    params.knowledges.map((item, index) => {
      let obja = {
        id: index + 1,
        name: item.title,
        key: item.id,
        keys: item.keys,
        category: 1
      };
      let objb = {
        source: 0,
        target: index + 1,
        name: " "
      };
      nodes.push(obja);
      links.push(objb);
    });
  let data = {
    nodes: nodes,
    links: links
  };

  const color1 = "#006acc";
  // const color2 = "antiquewhite";
  const color2 = "#fff";

  data.nodes.forEach(node => {
    if (node.category === 0) {
      node.symbolSize = 80;
      node.itemStyle = {
        color: color1
      };
    } else if (node.category === 1) {
      node.itemStyle = {
        color: color2
      };
    }
  });

  data.links.forEach(link => {
    link.label = {
      align: "center",
      fontSize: 12
    };
  });

  let categories = [
    {
      id: 0,
      itemStyle: {
        color: color1,
        size: 200
      }
    },
    {
      name: "董事",
      itemStyle: {
        color: color2
      }
    }
  ];
  const option = {
    series: [
      {
        type: "graph",
        layout: "force",
        symbolSize: 80,
        draggable: true,
        roam: true,
        focusNodeAdjacency: true,
        categories: categories,
        edgeSymbol: ["", "arrow"],
        edgeSymbolSize: [80, 10],
        edgeLabel: {
          normal: {
            show: true,
            textStyle: {
              fontSize: 20
            },
            formatter(x) {
              return x.data.name;
            }
          }
        },
        label: {
          show: true
        },
        force: {
          repulsion: 2000,
          edgeLength: 120
        },
        data: data.nodes,
        links: data.links
      }
    ]
  };
  return option;
}
